'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ManageBidchargeCtrl
 * @description
 * # ManageBidchargeCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ManageBidchargeCtrl', function($scope, openApi, Util, $location, $routeParams, FormSubmit) {
        $scope.choosePeople = function() {
            var relModuleObj = {
                name: "ManageBidchargeCtrl",
                selectTab: "deposit_select_project",
                selectTabContent: "工程名称"
            };
            Util.savaParamForReview($scope.param, $routeParams.id);
            Util.savaDataforsearch(relModuleObj);

            $location.path("finance/choosepeople")
        };

        $scope.submit = function() {
            if (!$scope.param.projectName) {
                Util.Toast("请选择工程名称");
                return;
            }
            if (!$scope.param.userName) {
                Util.Toast("请输入交款人");
                return;
            }
            if (!$scope.param.amount) {
                if ($scope.param.amount !== 0) {
                    Util.Toast("请输入本次收款金额");
                    return;
                }
            }
            // 提交
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.bidCharge
            var options = {};
            options.urlParam = urlParam;
            var myDest = {};
            options.param = angular.copy($scope.param, myDest);
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显
            // 如果是修改页面的话则提交的地址不一样，参数一样
            if (TVtype == Util.UPDATE) {
                options.url = openApi.ip + openApi.bidCharge
            }
            // 数据回显时候与发起时候的格式不一样，需要依次获取
            options.param["formBidApply.formId"] = options.param["formBidApply.formId"] || options.param.formBidApply.formId || "";
            delete options.param.formBidApply
            new FormSubmit(options);
        };

        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function(data) {
                $scope.param = data;
            });
        };
        // 初始化
        init();
    });
